package com.xing.binbackend.pattern.strategy33.operation.performance;

import com.xing.binbackend.topology.model.Edge;
import com.xing.binbackend.topology.model.Event;
import com.xing.binbackend.topology.model.Vertex;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class PerformanceServiceImpl {
    public void process(List<Event> events) {
        Map<String, List<String>> resTypeToResTye = events.stream().collect(Collectors.groupingBy(Event::getResType,
                Collectors.mapping(Event::getResId, Collectors.toList())));
        List<Vertex> vertices = new ArrayList<>();
        List<Edge> edges = new ArrayList<>();
        // 策略执行
        CollectorProcessor processor = new CollectorProcessor();
        for (Map.Entry<String, List<String>> entry : resTypeToResTye.entrySet()) {
            String resType = entry.getKey();
            List<String> resIds = entry.getValue();
            switch (resType) {
                case "PhysicalServer":
                    processor.register(new PServerCollector(resIds));
                    break;
                case "VirtualMachine":
                    processor.register(new VMCollector(resIds));
                    break;
                //....不断扩展
            }
        }
        processor.processRequest(vertices, edges);
    }
}

